﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ExpressionUtil.Parser.Handler
{
    /// <summary>
    /// 布尔类型常量解析程序
    /// </summary>
    internal class ConstBoolHandler : ParseHandlerBase
    {
        /// <summary>
        /// 默认构造函数
        /// </summary>
        public ConstBoolHandler()
        {
            this.next = new VariableHandler();
        }

        /// <summary>
        /// 解析元素
        /// </summary>
        /// <param name="context">解析参数</param>
        /// <param name="element">需要解析的元素</param>
        /// <returns>是否已解析</returns>
        protected override bool ParseCore(string element, ParseContext context)
        {
            bool ret = false;
            bool temp;
            if (bool.TryParse(element, out temp))
            {
                Node.ConstBoolNode num = new Node.ConstBoolNode(temp);
                context.PostfixStack.Push(num);
                context.IncreaseFunctionParameterCount();
                ret = true;
            }
            return ret;
        }
    }
}
